/**
  ******************************************************************************
  * @file    Devices_E22.c
  * @author  AnshininTakaha
  * @version V1.21
  * @date		 2021/09/27
  * @brief   The File of E22(RF) Init Modify
	* @copyright (c) 2017-2021 JZI. All rights reserved.
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "Devices_E22.h"
#include "gpio.h"
#include "BSP_USART.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/



/* Exported mention ----------------------------------------------------------*/
void E22_RF_Setting(uint16_t Address,uint8_t Channel);

/* Exported variables --------------------------------------------------------*/
/*E22 using Function*/
E22_Fuc E22_Function = E22_FucGroundInit;
#undef E22_FucGroundInit


/**
 * @brief E22 Module setting function.
 * @param Address  The E22 Module confirm Address
 * @param Channel  The E22 Module confirm Channel
 * @attention The E22 Address & Channel must be the same.
							Both Transfer Node(s) and Receive Node(s).
 * @return void.
 */
void E22_RF_Setting(uint16_t Address,uint8_t Channel)
{
	/* Store for Reset & Setting Data */
	uint8_t Soft_Reset[6] = {0};
	/* Get Default Setting from Grand */
	E22_Setting_t E22Setting = {RF433_CONFIG_PACK};
	
	/* Set E22 Into Setting Mode */
	MD0_LOW();
	MD1_HIGH();
	HAL_Delay(100);
	
	/* Change Custom Modify Address & Channal */
	E22Setting.Address_L = (Address >> 8) & 0xFF;
	E22Setting.Address_H = (Address) & 0xFF;
	E22Setting.Channal = Channel % E22_CHANNEL_MAX;
	
	/* Send Data for Setting E22 */
	/* Then Waitting Transfer Complete */
	send_data_dma_u1(E22Setting.E22_SettingMessage,12);
	HAL_Delay(100);
	
	/* E22 Soft Reset */
	Soft_Reset[0] = 0xC4;
	Soft_Reset[1] = 0xC4;
	Soft_Reset[2] = 0xC4;
	
	/* Send Data for Setting E22 */
	/* Then Waitting Transfer Complete */
    send_data_dma_u1(Soft_Reset,3);
	HAL_Delay(100);
	
	/* Set E22 Into Working Mode */
	MD0_LOW();
	MD1_LOW();
	HAL_Delay(100);
	
}




/* End -----------------------------------------------------------------------*/
